<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>测试上传</title>
</head>

<script type="text/javascript">
    function savePic(){
        var formData = new FormData($( "#uploadPic" )[0]);
        var ajaxUrl = "${path}/file/saveHeaderPic";
        //alert(ajaxUrl);
        //$('#uploadPic').serialize() 无法序列化二进制文件，这里采用formData上传
        //需要浏览器支持：Chrome 7+、Firefox 4+、IE 10+、Opera 12+、Safari 5+。
        $.ajax({
            type: "POST",
            //dataType: "text",
            url: ajaxUrl,
            data: formData,
            async: false,
            cache: false,
            contentType: false,
            processData: false,
            success: function (data) {
                console.log(data)
            },
            error: function(data) {
                console.log("上传出错：")
                console.log(data)
                console.log(data.responseText)
            }
        });
        return false;
    }
</script>

<body>


<form id="uploadPic" action="#" enctype="multipart/form-data">
    <input type="file" name="file">
    <a href="javascript:savePic();" class="btn green"> 提交 </a>
</form>


</body>
</html>